<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<#include "*/common/common.html">

<title>WebStar Page</title>
</head>
<body>
<div class="site_address">
	<i class="fa fa-flag" style="color:blue;"></i><font>例子</font> <i class="fa fa-angle-right"></i> <font>demo_foot</font>
	<span class="pull-right">
		<a class="btn btn-default btn-sm"><i class="fa fa-search"></i></a>
		<a class="btn btn-primary btn-sm" onclick="addColumn();"><i class="fa fa-plus"></i> 添加</a>
	</span>
</div>
<table id="foot-table"></table>
<div id="foot-pager"></div>

<script>
var tomise_jqgrid;
(function(){
	var item_table = "#foot-table";
	var item_pager = "#foot-pager";
	$(window).on('resize',function(){
		$(item_table).jqGrid('setGridWidth',$(".right-content").css("width"));	
	});
	tomise_jqgrid = $(item_table).jqGrid({
	   	url:'/demo/foot/query',
		datatype: "json",
		mtype:"post",
	   	colNames:['编号','起点','终点', '时间', '天气','心情','感悟','操作'],
	   	colModel:[
	   		{name:'ID',index:'ID', width:30,align:"center",hidden:true},
	   		{name:'START_POINT',index:'startPoint', width:120,align:"center"},
	   		{name:'END_POINT',index:'endPoint', width:90,align:"center"},
	   		{name:'FOOT_TIME',index:'footTime', width:100,formatter:formateDate,align:"center"},
	   		{name:'WEATHER',index:'weather', width:120, align:"center"},
	   		{name:'HEART',index:'heart', width:100, align:"center"},		
	   		{name:'MIND',index:'mind', width:300,align:"left"},		
	   		{name:'operation',index:'operation', width:150,align:"center",sortable:false,formatter:formatOperation}		
	   	],
	   	rowNum:10,
	   	rowList:[5,10],
	   	pager: item_pager,
	   	sortname: 'FOOT_TIME',
	   	height:'90%',
	   	width:'99%',
	    viewrecords: true,
	    sortorder: "desc",
	    rownumbers: false, 
	    altRows: true,
        /* 定义排序字段与排序方式 */
        forceFit: true,
        //toppager: true,
        multiselect: true,
        //multikey: "ctrlKey",
        multiboxonly: false,
        autoheight:true,
        autowidth: true
	    
	});
	$(item_table).jqGrid("navGrid",item_pager,{
		del:true,add:false,edit:false,search:false,
		delfunc : function(rowid) {
			var selectArray = $(item_table).jqGrid("getGridParam","selarrrow");
			var id = "";	
			$.each(selectArray,function(i,item){
				if(i>0) {
					id +="," ;
				}
				id +=tomise_jqgrid.getRowData(item).ID;
			});
			Power.dialog.confirm("是否要删除?", function() {					
				var cmd = new Power.command("/demo/foot", "post");
				cmd.setParameter("id",id);
				alert(id);
				var ret = cmd.execute("delete");
				if (!ret.error && ret.state == 1) {
					Power.dialog.alertSuccess("删除成功!");
					tomise_jqgrid.trigger("reloadGrid");
					return true;
				} else {
					Power.dialog.alertError("删除失败!");
					return false;
				}
			});
		}
	});
})();
/*编辑　　删除　*/
function formatOperation(cellvalue, options, cell){
	var id = cell["ID"];
	return "<span class='btn btn-primary btn-mini' onclick=editColumn('"+id+"') title='编辑'><i class='fa fa-pencil'></i>&nbsp;编辑</span>";
};
/**
 *格式化时间
 */
function formateDate( cellvalue, options, cell ) {
    if(cellvalue!=null){
        var date = new Date(cellvalue);
        return date.format("yyyy-MM-dd");
    }
    return "";
};
/**
 *新增对象
 */
function addColumn(){ 
	var addButtons = [{
		id:'foot-add',
	    name: '确定',
	    callback: function () {
	    	if(submit()){
	    		return true;
	    	}else{
	        	return false;	
	    	}
	    },
	    focus: true
	}, {
	    name: '取消'
	}];

	Power.dialog({
		id:"foot-add-dialog",
		title:"添加足迹",
		url : "/demo/foot/add",
		top:0,
		width:800,
		button:addButtons,
		init:function(){
		
		},
		close:function(){
			tomise_jqgrid.trigger("reloadGrid");
		}
	});
	
};
/**
 *编辑对象
 */
function editColumn(id){ 
	var addButtons = [{
		id:'foot-edit',
	    name: '确定',
	    callback: function () {
	    	if(submit()){
	    		return true;
	    	}else{
	        	return false;	
	    	}
	    },
	    focus: true
	}, {
	    name: '取消'
	}];

	Power.dialog({
		id:"foot-edit-dialog",
		title:"编辑足迹",
		url : "/demo/foot/edit?id="+id,
		top:0,
		width:800,
		button:addButtons,
		init:function(){
		
		},
		close:function(){
			tomise_jqgrid.trigger("reloadGrid");
		}
	});
	
};
</script>
</body>
</html>
